class MyCalendar {
    set<pair<int, int>> booked;

public:
    bool book(int start, int end) {
        auto it = booked.lower_bound({ end, 0 });

        if (it == booked.begin() || (--it)->second <= start)
        {
            booked.emplace(start, end);
            return true;
        }

        return false;
    }
};
